#include<stdio.h>
#include"ohos_init.h"
#include "cmsis_os2.h"
void myfunc(void *arg)
{
    while(1)
    {
        printf("nihao,\n");
        sleep(1);
    }
}
void mytimer(void *arguement)
{
    printf("zaoshanghao,\n");
}
//main函数
void mytest(void)
{
    osThreadAttr_t attr;
    osThreadId_t id;
    osThreadAttr_t timerattr;
    osThreadId_t timerID;
    int ret;
    printf("hello group16\n");
  
    attr.name="mytest";
    attr.cb_mem=NULL;
    attr.cb_size=0;
    attr.stack_mem=NULL;
    attr.stack_size=1024;
    attr.attr_bits=0;
    attr.priority=osPriorityNormal;


//创建线程

    id=osThreadNew(myfunc,NULL,&attr);
    if(id==NULL)
    {
        printf("Create Thread failed.\n");
        return;
    }
    printf("Create Thread failed.\n");

    timerattr.name="mytimer";
    timerattr.attr_bits=0;
    timerattr.cb_mem=NULL;//系统自动分配
    timerattr.cb_size=0;//系统自动分配

 

    //创建定时器
    timerID=osTimerNew(mytimer,osTimerPeriodic,NULL,&timerattr);
    if(timerID==NULL)
    {
        printf("Create timer failed.\n");
        return;
    }
    printf("Create timer success.\n");
    ret=osTimerStart(timerID,500);
    if(ret!=osOK)
    {
        printf("Start timer failed.,%d\n",ret);
        return;
    }
    printf("Start timer success.\n");
}
SYS_RUN(mytest);
